const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // array: ["违规信息", "虚假交付", "涉嫌抄袭","其他"],
    array:[
      {
        name:"违规信息",
        value:0,
      },
      {
        name:"虚假交付",
        value:1,
      },
      {
        name:"涉嫌抄袭",
        value:2,
      },
      {
        name:"其他",
        value:3,
      },
    ],
    autoObj:{
      minHeight: 100
    },
    protectionVal:'违规信息',
    reportListShow:false,
    index: 0,
    taskid:'',
    workid:'',
    descVal:'',
    protectionType:'',//==1是雇佣维权==2是作品维权
    hireId:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options,'options---==-')
    if (options.id){
      this.setData({
        hireId:options.id,
        protectionType: options.protectionType
      })
    }
    this.setData({
      taskid: options.taskid,
      workid: options.workid
    })
  },

  typeChange(){
    this.setData({
      reportListShow: true
    })
  },
  onCloseReportList(){
    this.setData({
      reportListShow: false
    })
  },

  onSelectReportList(event){
    this.setData({
      index:event.detail.value,
      protectionVal:event.detail.name,
    })
  },

  // 维权描述
  descInp:function(e){
    this.setData({
      descVal: e.detail.value
    })
  },
  // 维权类型
  bindPickerChange:function(e){
    this.setData({
      index: e.detail.value
    })
  },
  // 提交
  submitBtn:function(){
    var _this = this
    var { index, taskid, workid, descVal, protectionType, hireId } = this.data
    console.log(protectionType,'protectionType')
    console.log(hireId,'hireId')
    if (descVal == ''){
      wx.showToast({
        title: '请输入维权原因',
        icon: 'none',
        duration: 2000
      })
      return false;
    }
    if (protectionType == ''){
      var url = app.globalData.baseUrl + 'work/deliveryRight';
      var data = {
        work_id: workid,
        type: parseInt(index) + 1,
        desc: descVal,
        task_id: taskid,
        token: app.globalData.token
      }
    } else if (protectionType == 1){
      var url = app.globalData.baseUrl + 'user/employRights';
      var data = {
        employ_id: hireId,
        type: parseInt(index) + 1,
        desc: descVal,
        token: app.globalData.token
      }
    } else if (protectionType == 2){
      var url = app.globalData.baseUrl + 'user/rightGoods';
      var data = {
        order_id: hireId,
        type: parseInt(index) + 1,
        desc: descVal,
        token: app.globalData.token
      }
    }
    wx.showLoading({
      title: '加载中',
    })
    app.wxPostRequest(url, data, (res) => {
      console.log(res)
      wx.hideLoading()
      if (res.code == 1000) {
        wx.showToast({
          title: '提交成功',
          icon: 'success',
          duration: 2000
        })
        setTimeout(function () {
          const  pages=getCurrentPages();
          const beforepage=pages[pages.length-2]
          wx.navigateBack({
            delta: 1,
            success:function (){
              beforepage.orderDatail()
            }
          })
        }, 2000)
      }
    }, (err) => {
      wx.hideLoading()
      wx.showToast({
        title: err.data.message,
        icon: 'none',
        duration: 2000
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
